package quickSort;

public class QuickSort {

	public static void main(String[] args) {
		int[] a = {3,5,8,1,6,2,0,7,4,9,-1,2};
		quickSork(a,0,a.length-1);
		printArray(a);
	}
	private static void quickSork(int[] a, int low, int high) {
		int l = low;
		int h = high;
		int midel = a[low];//默认选区第一位作为分隔位
		while (low < high) {
			while (low<high&&a[high]>=midel)
				high--;
			if (low<high) {
				a[low++] = a[high];
			}
			while (low<high&&a[low]<=midel)
				low++;
			if (low<high) {
				a[high--] = a[low];
			}
		}
		a[low] = midel;
		if(l<low)
			quickSork(a, l, low-1);
		if(low<h)
			quickSork(a, low+1, h);
	}
	/**
	 * 打印输出数组a到控制台
	 * @param a
	 */
	private static void printArray(int[] a) {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i]+"\t");
		}
	}
	/**
	 * 交换数组中两个位置的值
	 * @param a
	 * @param i
	 * @param index
	 */
	private static void swap(int[] a, int i, int index) {
		int temp = 0;
		temp = a[i];
		a[i] = a[index];
		a[index] = temp;
	}
	

}
